package com.ruoyi.worker.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.worker.domain.WorkCheck;
import com.ruoyi.worker.mapper.WorkCheckMapper;
import com.ruoyi.worker.service.IWorkCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 岗前检查记录Service业务层处理
 *
 * @author wng
 * @date 2024-08-04
 */
@Service
public class WorkCheckServiceImpl implements IWorkCheckService {
    @Autowired
    private WorkCheckMapper workCheckMapper;

    /**
     * 查询岗前检查记录
     *
     * @param id 岗前检查记录主键
     * @return 岗前检查记录
     */
    @Override
    public WorkCheck selectWorkCheckById(Long id) {
        return workCheckMapper.selectWorkCheckById(id);
    }

    /**
     * 查询岗前检查记录列表
     *
     * @param workCheck 岗前检查记录
     * @return 岗前检查记录
     */
    @Override
    public List<WorkCheck> selectWorkCheckList(WorkCheck workCheck) {

        if (workCheck.getParams().containsKey("checkTimeStart") && workCheck.getParams().containsKey("checkTimeEnd")) {
            if (workCheck.getParams().get("checkTimeStart") != null && !"".equals(workCheck.getParams().get("checkTimeStart"))
                    && workCheck.getParams().get("checkTimeEnd") != null && !"".equals(workCheck.getParams().get("checkTimeEnd"))) {
                workCheck.getParams().put("checkTimeStart", workCheck.getParams().get("checkTimeStart") + " 00:00:00");
                workCheck.getParams().put("checkTimeEnd", workCheck.getParams().get("checkTimeEnd") + " 23:59:59");
            }

        }

        return workCheckMapper.selectWorkCheckList(workCheck);
    }

    /**
     * 新增岗前检查记录
     *
     * @param workCheck 岗前检查记录
     * @return 结果
     */
    @Override
    public int insertWorkCheck(WorkCheck workCheck) {
        workCheck.setCreateTime(DateUtils.getNowDate());
        return workCheckMapper.insertWorkCheck(workCheck);
    }

    /**
     * 修改岗前检查记录
     *
     * @param workCheck 岗前检查记录
     * @return 结果
     */
    @Override
    public int updateWorkCheck(WorkCheck workCheck) {
        workCheck.setUpdateTime(DateUtils.getNowDate());
        return workCheckMapper.updateWorkCheck(workCheck);
    }

    /**
     * 批量删除岗前检查记录
     *
     * @param ids 需要删除的岗前检查记录主键
     * @return 结果
     */
    @Override
    public int deleteWorkCheckByIds(Long[] ids) {
        return workCheckMapper.deleteWorkCheckByIds(ids);
    }

    /**
     * 删除岗前检查记录信息
     *
     * @param id 岗前检查记录主键
     * @return 结果
     */
    @Override
    public int deleteWorkCheckById(Long id) {
        return workCheckMapper.deleteWorkCheckById(id);
    }
}
